<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2019/10/18
  Time: 14:28
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>修改岗位</title>
    <%
        String basePath = request.getScheme()+"://"+request.getServerName()+":"
                +request.getServerPort()+request.getContextPath()+"/";
    %>
    <base href="<%=basePath%>">
    <script type="text/javascript" src="js/jquery-1.12.3.min.js"></script>
    <script type="text/javascript">
        function  checkName(){
            $("#pnametip").empty();
           var pname =  $("#pname").val();
           if(pname == ""){
                $("#pnametip").html("<span style='color: red'>职位名称不能为空</span>");
                return false;
           }
           return true;
        }

        function  checkMinSal(){
            $("#minSaltip").empty();
            var minSal =  $("#minSal").val();
            if(minSal == ""){
                $("#minSaltip").html("<span style='color: red'>最低工资不能为空</span>");
                return false;
            }
            return true;
        }

        function  checkMaxSal(){
            $("#maxSaltip").html("");
            var maxSal =  $("#maxSal").val();
            if(maxSal == ""){
                $("#maxSaltip").html("<span style='color: red'>最高工资不能为空</span>");
                return false;
            }
            return true;
        }

        function checkForm(){
            var flag1 = checkName();
            var flag2 = checkMinSal();
            var flag3 = checkMaxSal();
            if(flag1 && flag2 && flag3){
                return true;
            }else{
                return false;
            }
        }
        //页面加载完后获取所有的公司列表并写入到下拉列表中
        $( function(){
            $.ajax({
                url:"findAllComp.action",
                success:function(arr){
                   //1.拼接option字符串
                    var str = "";
                    for(var i=0;i<arr.length;i++){
                        if(arr[i].cid==${position.cid}){
                            str += '<option value="'+arr[i].cid+'" selected>'+arr[i].cname+'</option>';
                        }else{
                            str += '<option value="'+arr[i].cid+'" >'+arr[i].cname+'</option>';
                        }
                    }
                    //2.添加到select中
                    $("#cid").html(str);
                }
            });
        });
    </script>
</head>
<body>
    <h2>发布岗位招聘信息</h2>
    <hr>
    <form action="updatePosition.action" method="post" onsubmit="return checkForm()">
        <table>
            <tr>
                <td>职位编号</td>
                <td>
                    <input type="text" id="pid" name="pid" value="${position.pid}"  readonly>
                </td>
            </tr>
            <tr>
                <td>职位名称</td>
                <td>

                    <input type="text" id="pname" name="pname" value="${position.pname}" onblur="checkName()">
                    <span id="pnametip"></span>
                </td>
            </tr>
            <tr>
                <td>最低薪水</td>
                <td>
                    <input type="text" id="minSal" name="minSal" value="${position.minSal}" onblur="checkMinSal()">
                    <span id="minSaltip"></span>
                </td>
            </tr>
            <tr>
                <td>最高薪水</td>
                <td>
                    <input type="text" id="maxSal" name="maxSal" value="${position.maxSal}" onblur="checkMaxSal()">
                    <span id="maxSaltip"></span>
                </td>
            </tr>
            <tr>
                <td>发布公司</td>
                <td>
                    <select name="cid" id="cid">

                    </select>
                </td>
            </tr>
            <tr>
                <td colspan="2">
                    <input type="submit" value="发布">
                </td>
            </tr>
        </table>
    </form>

    ${error}
</body>
</html>
